<template>
    <el-tree 
      :data="datamy" 
      show-checkbox
      :props="defaultProps" 
      node-key="id"
      default-expand-all  
      ref="tree">
    </el-tree>
</template>
<script>
import { getRightItemAll } from '@/api/user';
export default { 
  props:['data'],
  data(){
    return{
      defaultProps: { children: 'children',  label: 'label'},
      id:1,
      expkey:[],
      datamy:[],
      tree:[],
      teep:{vue:1,id:0}
    };
  },
  created() {
    // this.TreeRefresh();
  },
  methods:{
    TreeRefresh(val){
      this.datamy=[];
      this.expkey=[],
      this.teep.id=val;
      getRightItemAll().then(rsp => {
        //console.log(rsp);
        if (rsp.code === 0) { 
          this.datamy=rsp.data; 
          this.expkey = [this.id];     
        }
      });
    },
    getCheckedKeys(){
      this.tree=this.$refs.tree.getCheckedKeys();
      console.log('this.tree'+this.tree);
      this.$emit('change',this.tree); //返回整个数组
    },
    setCheckedKeys(value) {
      console.log('sssss  '+value);
      this.$refs.tree.setCheckedKeys(value);
    },
  }  
};
</script>

